package services

import (
	"colly/template"
	"colly/types"
	"github.com/hibiken/asynq"
)

func PubOfferTask(queue *asynq.Client, item types.ServerData) (t *asynq.TaskInfo, e error) {
	data := make(map[string]interface{})
	data["title"] = item.Title
	data["service_id"] = item.ServiceID
	data["sku"] = item.BrandID
	data["currency"] = item.DisplayCurrency
	data["price"] = item.DisplayPrice
	data["collection_id"] = item.OfferAttributes[0].CollectionID
	data["dataset_id"] = item.OfferAttributes[0].DatasetID
	data["score"] = item.Score
	task, err := template.NewOfferTask(data)
	if err != nil {
		return nil, err
	}
	info, err := queue.Enqueue(task)
	if err != nil {
		return nil, err
	}
	return info, nil
}
